package com.wtgroup.demo.common.util;


import java.util.Random;


/**
 * @author L&J
 * @version 0.0.0
 * @email liuhejun108@163.com
 * @date 2019/9/9 13:46
 */
public class RandomUtil extends cn.hutool.core.util.RandomUtil {
    // 键盘上的字符
    public static final String BASE_KEY_BOARD = "QWERTYUIOPLKJHGFDSAZXCVBNMqwertyuioplkjhgfdsazxcvbnm0123456789`~!@#$%^&*()_+-=[]{}\\;':\"|\n,./<>?";

    /**
     * 生成随机整型数组
     * @param length 数组长度
     * @param origin 开始
     * @param bound 数值范围(最大值, 不含)
     */
    public static int[] randomArray(int length, int origin, int bound) {

        int[]  arr = new int[length];
        // if (range == 0) range = 100; //设置默认为100. err?
        for ( int i = 0; i < length; i++ ) {
            arr[i] = cn.hutool.core.util.RandomUtil.randomInt(origin, bound);
        }
        return arr;
    }


    /**
     * 带种子随机数组
     */
    public static int[] randomArray(int length, int origin, int bound, int seed ) {

        int[]  arr = new int[length];
        Random rd  = new Random(seed);
        // if (range == 0) range = 100; //设置默认为100. err?
        for ( int i = 0; i < length; i++ ) {
            arr[i] = (int) (origin + (bound-origin) * rd.nextDouble());
        }
        return arr;
    }

    /**
     * 生成有序整型数组(升序)
     * <p>
     * I: 数组长度N, 生成值0~N-1的数组
     */
    public static int[] range(int length) {
        return range(length, 0);
    }

    public static int[] range(int length, int start) {
        int[] arr = new int[length];
        for (int i = 0; i < length; i++) {
            arr[i] = i + start;
        }
        return arr;
    }


    public static String[] randomArrayString(int length, int maxStrLen, int seed) {
        return randomArrayString(length, maxStrLen, seed, BASE_CHAR_NUMBER.toCharArray());
    }

    /**
     * 生成随机字符串数组
     * @param length
     * @param maxStrLen
     * @param seed
     */
    public static String[] randomArrayString(int length, int maxStrLen, int seed, char[] strPool) {
        Random rd  = new Random(seed);
        String[] strings = new String[length];
        for (int i = 0; i < length; i++) {
            int sl = rd.nextInt(maxStrLen)+1;
            StringBuilder sb = new StringBuilder(sl);
            for (int j = 0; j < sl; j++) {
                sb.append(strPool[rd.nextInt(strPool.length)]);
            }
            strings[i] = sb.toString();
        }

        return strings;
    }

}
